{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16f0bd63-25f8-4cdd-9251-e32665c8d648",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Purpose**\n",
    "This notebook is a tutorial for ZapMeNot."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "15c0baec-8c9e-49b1-849f-253918b1ce51",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Configure for the Tutorial**\n",
    "This step won't be required for production work.  The module search path is being altered to preferentially run\n",
    "the \"nightly builds\" of both WatpropPy and ZapMeNot."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af8f7830-2a87-4b73-987a-dfc5dd0a1924",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import sys\n",
    "sys.path.insert(0,'/naf/rad/workshop/packages/WatpropPy')\n",
    "sys.path.insert(0,'/naf/rad/workshop/packages/ZapMeNot')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95307531-80eb-4d43-800b-7fac0fa33255",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Import packages**\n",
    "The Python packages required by this notebook are imported. The package and Python interpreter versions are printed to ensure analysis reproducibility. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0661b3e5-7ffc-4101-b1fc-0db83f9864a5",
   "metadata": {},
   "outputs": [],
   "source": [
    "from IPython.display import display, Markdown, Math, Latex, Javascript, HTML\n",
    "from scipy import interpolate\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import math\n",
    "from zap_me_not import model,source,shield,detector,material\n",
    "import pyvista as pv\n",
    "import WatpropPy"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2ab16a25-d66f-43f1-a851-2eb6b512c1ff",
   "metadata": {},
   "source": [
    "# **Problem Descripton**\n",
    "Modified version of ESIS benchmark shielding problem \\#1.\n",
    "\n",
    "The source is a water-filled tank 6 ft high and 7 ft in diameter.\n",
    "The tank wall is steel with a thickness of 1 inch.\n",
    "Uniformly distributed in the water is a source containing\n",
    "10 Ci of Co<sup>60</sup>, 4,300 Bq of Cr<sup>48</sup>, and an unknown\n",
    "isotope with a 0.4 MeV photon with an intensity of 3.0E+4 photons/sec/cm<sup>3</sup>.\n",
    "  \n",
    "The  detector location is 20 ft from the tank centerline\n",
    "at the vertical centerline of the tank.\n",
    "A concrete shield wall between tank and detector is located 10 ft\n",
    "from the tank wall and is 6 in thick.\n",
    "The water has a temperature of 76 degF at a pressure of 14.7 psia. \n",
    "The air density is 0.00122 g/cm3.\n",
    "The the steel density is 7.8 g/cm<sup>3</sup>.\n",
    "The concrete density is 2.4 g/cm<sup>3</sup>.  \n",
    "The buildup material is concrete.\n",
    "\n",
    "Update: Water temperature changed to 170 degF.\n",
    "\n",
    "Update: Add 125 curies of I-131 to the source.\n",
    "\n",
    "Update: Add 300 curies of Cs-137 to the source.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "951df480-f82c-4413-8bf2-76459c1ca7c5",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Conversion of Units to CGS**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dcef25fd-e8da-40ed-b6f7-3fca5432c72d",
   "metadata": {},
   "outputs": [],
   "source": [
    "def in_to_cm(length):\n",
    "    return length*2.54\n",
    "\n",
    "def ft_to_cm(length):\n",
    "    return length*12*2.54\n",
    "\n",
    "english = WatpropPy.units.english\n",
    "si = WatpropPy.units.si\n",
    "\n",
    "tank_height_cm = ft_to_cm(6)\n",
    "tank_inner_radius_cm = ft_to_cm(7/2)\n",
    "tank_wall_thickness_cm = in_to_cm(1)\n",
    "tank_outer_radius_cm = tank_inner_radius_cm + tank_wall_thickness_cm\n",
    "\n",
    "detector_distance_cm = ft_to_cm(20)\n",
    "\n",
    "concrete_shield_thickness_cm = in_to_cm(6)\n",
    "concrete_shield_inner_edge_cm = ft_to_cm(10) + tank_outer_radius_cm\n",
    "concrete_shield_outer_edge_cm = concrete_shield_inner_edge_cm + concrete_shield_thickness_cm\n",
    "\n",
    "water_density_mks = 1/(WatpropPy.v_pt(14.7, 170, english, si))\n",
    "water_density_cgs = water_density_mks / 1000\n",
    "\n",
    "display(Markdown(f\"**tank height = {tank_height_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**tank inner radius = {tank_inner_radius_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**tank wall thickness = {tank_wall_thickness_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**tank outer radius = {tank_outer_radius_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**detector location = {detector_distance_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**concrete shield inner edge = {concrete_shield_inner_edge_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**concrete shield thickness = {concrete_shield_thickness_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**concrete shield outer edge = {concrete_shield_outer_edge_cm:2.4} cm**\"))\n",
    "display(Markdown(f\"**water density = {water_density_cgs:2.4} g/cc**\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "197c5138-cb0b-4eda-ba92-05dfca5a0c7d",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Model Construction**\n",
    "The centerline of the tank will be on the Z axis.  The dose point will be located along\n",
    "and above the X axis."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "23fb681e-13ef-422e-b76f-efd986819784",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# build the source, including dimensions, materials, and source composition\n",
    "my_source = source.ZAlignedCylinderSource(material_name=\"water\", density=water_density_cgs, \\\n",
    "    cylinder_radius=tank_inner_radius_cm, \\\n",
    "    cylinder_center=[0, 0, tank_height_cm/2], cylinder_length=tank_height_cm)\n",
    "my_source.add_isotope_curies('Co-60',10)\n",
    "my_source.add_isotope_bq('Cr-48',4300)\n",
    "my_source.add_photon(0.4,3.0E+4)\n",
    "my_source.add_isotope_curies('I-131',125)\n",
    "my_source.add_isotope_curies('Cs-137',300)\n",
    "my_source.points_per_dimension = [16,16,16]\n",
    "\n",
    "# create the overall geometry\n",
    "tank_model = model.Model()\n",
    "tank_model.add_source(my_source)\n",
    "\n",
    "# add the tank wall\n",
    "tank_model.add_shield(shield.ZAlignedInfiniteAnnulus(\"iron\", \\\n",
    "    cylinder_inner_radius=tank_inner_radius_cm, \\\n",
    "    cylinder_center=[0, 0, tank_height_cm/2], \\\n",
    "    cylinder_outer_radius=tank_outer_radius_cm, density=7.8))\n",
    "\n",
    "# add the concrete shield\n",
    "tank_model.add_shield(shield.SemiInfiniteXSlab(\"concrete\", x_start=concrete_shield_inner_edge_cm, \\\n",
    "       x_end=concrete_shield_outer_edge_cm, density=2.4))\n",
    "\n",
    "# add the air, buildup factor, and detector\n",
    "tank_model.set_filler_material('air',density=0.00122) # g/cc\n",
    "tank_model.set_buildup_factor_material(material.Material('concrete'))\n",
    "tank_model.add_detector(detector.Detector(detector_distance_cm, 0, tank_height_cm/2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ad28ed7e-d892-4c76-999e-696ccdbaf435",
   "metadata": {
    "tags": []
   },
   "source": [
    "# **Calculate Dose Rate**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ca8c6c72-f89e-41df-9ec3-34a72de37579",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "result = tank_model.calculate_exposure()\n",
    "display(Markdown(f\"**dose rate = {result:2.3} mR/hr**\"))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "01abe34b-dd72-4d5d-a00a-59e71dfce961",
   "metadata": {},
   "source": [
    "# **Plot the Geometry**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "50fd58ba-7e11-4c84-9f1c-27ec65409e72",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "pv.set_jupyter_backend('ipygany')\n",
    "tank_model.display()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "84b758e2-dac0-4810-a632-292fb130c1f0",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
